package com.itcast.rpc.client.cluster.impl;

import com.itcast.rpc.client.channel.ProviderService;
import com.itcast.rpc.client.cluster.ClusterStrategy;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("random")
public class RandomClusterStrategy implements ClusterStrategy {
    @Override
    public ProviderService select(List<ProviderService> services) {
        int MAX_lEN = services.size();
        int index = RandomUtils.nextInt(0, MAX_lEN);
        return services.get(index);
    }
}
